package com.notes.designpattern.chain.handler;

import com.alibaba.fastjson.JSON;
import com.notes.designpattern.chain.BusinHandler;
import com.notes.designpattern.chain.BusinHandlerChain;
import com.notes.designpattern.chain.domain.*;

/**
 * @author
 * @Describe 功能描述
 * @date
 */
public class BusinTwoHandler implements BusinHandler<BusinTwoReq, BusinTwoBO, BusinTwoResp> {

    String businName;

    public BusinTwoHandler(String businName) {
        this.businName = businName;
    }

    @Override
    public BusinTwoResp process(BusinTwoReq req, BusinTwoBO businTwoBaseBO, BusinHandlerChain businHandlerChain) {
        System.out.println("开始执行" + this.businName + "入参: " + JSON.toJSONString(req));
        BusinTwoResp businTwoResp = new BusinTwoResp();
        if (this.businName.equals("BusinTwoHandler")) {
            businTwoResp.setBusinResp("BusinTwoHandler");
            businTwoResp.setBusinOneResp(req.getBusinOneBaseResp());
            System.out.println("开始执行" + this.businName + "成功，出参: " + JSON.toJSONString(businTwoResp));
            BusinThreeReq nextChainReq = new BusinThreeReq();
            nextChainReq.setBusinKey("BusinThreeHandler");
            nextChainReq.setBusinTwoBaseResp(businTwoResp);
            businHandlerChain.process(nextChainReq, new BusinThreeBO(), businHandlerChain);
            return businTwoResp;
        }
        businTwoResp.setErrorNo(-1);
        System.out.println("开始执行" + this.businName + "失败，出参: " + JSON.toJSONString(businTwoResp));
        return businTwoResp;
    }
}
